package edu.gatech.cs2340.group7.wheresmystuffapp.presenters;

import java.util.List;

import edu.gatech.cs2340.group7.wheresmystuffapp.model.CustomDate;
import edu.gatech.cs2340.group7.wheresmystuffapp.model.DataManager;
import edu.gatech.cs2340.group7.wheresmystuffapp.model.DatabaseHelper;
import edu.gatech.cs2340.group7.wheresmystuffapp.model.Item;
import edu.gatech.cs2340.group7.wheresmystuffapp.model.ItemLocation;
import edu.gatech.cs2340.group7.wheresmystuffapp.views.ShowItemView;

public class ShowItemPresenter {
	private ShowItemView myView;
	
	public ShowItemPresenter(ShowItemView view) {
		myView = view;
		getItemInfo();
	}
	
	private void getItemInfo() {
		DatabaseHelper myHelper = new DatabaseHelper(myView);
		
		List<Item> items = myHelper.getAllItemsForUser(DataManager.getCurrentAccountName());
		
		Item item = items.get(items.size() - 1);
		String name = item.getName();
		String cat = item.getCategory();
		String desc = item.getDescription();
		ItemLocation il = item.getItemLocation();
		byte[] pic = item.getPicture();
		CustomDate date = item.getDateEntered();
		
		String itemDate = date.toString();
		String location = il.getLatitude() + " " + il.getLongitude();
		
		myView.setImage(pic);
		myView.setTextViews(name, desc, cat, itemDate, location);
	}
}
